/**
 * Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 * 
 * SPDX-License-Identifier: EPL-2.0
 */
package org.eclipse.xtend.core.tests.compiler;

import org.eclipse.xtend2.lib.StringConcatenation;
import org.junit.Ignore;
import org.junit.Test;

/**
 * @author Sebastian Zarnekow - Initial contribution and API
 */
@SuppressWarnings("all")
public class CompilerBug459920Test extends AbstractXtendCompilerTest {
  @Test
  public void regression_01() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import org.eclipse.xtext.util.concurrent.IUnitOfWork");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.util.concurrent.CancelableUnitOfWork");
    _builder.newLine();
    _builder.append("import org.eclipse.emf.ecore.resource.Resource");
    _builder.newLine();
    _builder.append("import org.eclipse.emf.ecore.resource.ResourceSet");
    _builder.newLine();
    _builder.append("import org.eclipse.xtext.util.CancelIndicator");
    _builder.newLine();
    _builder.append("class Main {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def <R, P extends Resource> R exec(IUnitOfWork<R, P> work, P param) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("if (work instanceof CancelableUnitOfWork<?,?>) {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("work.cancelIndicator = if (param === null)");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("[ true ]");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("else");
    _builder.newLine();
    _builder.append("\t\t\t\t");
    _builder.append("param.resourceSet.newCancelIndiciator");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("work.exec(param)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def CancelIndicator newCancelIndiciator(ResourceSet rs) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import org.eclipse.emf.ecore.resource.Resource;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.emf.ecore.resource.ResourceSet;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.util.CancelIndicator;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.util.concurrent.CancelableUnitOfWork;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.util.concurrent.IUnitOfWork;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.Exceptions;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class Main {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public <R extends Object, P extends Resource> R exec(final IUnitOfWork<R, P> work, final P param) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("try {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("R _xblockexpression = null;");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("{");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("if ((work instanceof CancelableUnitOfWork<?, ?>)) {");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("CancelIndicator _xifexpression = null;");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("if ((param == null)) {");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("final CancelIndicator _function = () -> {");
    _builder_1.newLine();
    _builder_1.append("              ");
    _builder_1.append("return true;");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("_xifexpression = _function;");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("} else {");
    _builder_1.newLine();
    _builder_1.append("            ");
    _builder_1.append("_xifexpression = this.newCancelIndiciator(param.getResourceSet());");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("          ");
    _builder_1.append("((CancelableUnitOfWork<?, ?>)work).setCancelIndicator(_xifexpression);");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("_xblockexpression = work.exec(param);");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _xblockexpression;");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} catch (Throwable _e) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("throw Exceptions.sneakyThrow(_e);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public CancelIndicator newCancelIndiciator(final ResourceSet rs) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void test_01() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Main {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def C pc() {");
    _builder.newLine();
    _builder.append("    \t");
    _builder.append("null");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def D pd() {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("null");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def A create if (flag) pc else pd p(String label, int num, boolean flag) {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("name = label");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("number = num");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("count = num");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface Named {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def String getName()");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def void setName(String name)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface A extends Named {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def int getNumber()");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def void setNumber(int n)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface B extends Named {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def int getCount()");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def void setCount(int c)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface C extends A, B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface D extends A, B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.util.ArrayList;");
    _builder_1.newLine();
    _builder_1.append("import java.util.HashMap;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class Main {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface Named {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("String getName();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void setName(final String name);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface A extends Main.Named {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("int getNumber();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void setNumber(final int n);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface B extends Main.Named {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("int getCount();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void setCount(final int c);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface C extends Main.A, Main.B {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface D extends Main.A, Main.B {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Main.C pc() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Main.D pd() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Main.A p(final String label, final int num, final boolean flag) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(label, num, flag);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("final Main.Named _result;");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("synchronized (_createCache_p) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("if (_createCache_p.containsKey(_cacheKey)) {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("return _createCache_p.get(_cacheKey);");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("Main.Named _xifexpression = null;");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("if (flag) {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("_xifexpression = this.pc();");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("} else {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("_xifexpression = this.pd();");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("_result = ((Main.A)_xifexpression);");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("_createCache_p.put(_cacheKey, (Main.A)_result);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("_init_p(_result, label, num, flag);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return (Main.A)_result;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private final HashMap<ArrayList<?>, Main.A> _createCache_p = CollectionLiterals.newHashMap();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private void _init_p(final Main.Named it, final String label, final int num, final boolean flag) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("it.setName(label);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("((Main.A)it).setNumber(num);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("((Main.B)it).setCount(num);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Test
  public void test_02() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Main {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def C pc() {");
    _builder.newLine();
    _builder.append("    \t");
    _builder.append("null");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def D pd() {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("null");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def create if (flag) pc else pd p(String label, int num, boolean flag) {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("name = label");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("number = num");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("count = num");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface Named {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def String getName()");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def void setName(String name)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface A extends Named {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def int getNumber()");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def void setNumber(int n)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface B extends Named {");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def int getCount()");
    _builder.newLine();
    _builder.append("\t    ");
    _builder.append("def void setCount(int c)");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface C extends A, B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("interface D extends A, B {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.util.ArrayList;");
    _builder_1.newLine();
    _builder_1.append("import java.util.HashMap;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class Main {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface Named {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("String getName();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void setName(final String name);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface A extends Main.Named {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("int getNumber();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void setNumber(final int n);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface B extends Main.Named {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("int getCount();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("void setCount(final int c);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface C extends Main.A, Main.B {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public interface D extends Main.A, Main.B {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Main.C pc() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Main.D pd() {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Main.Named p(final String label, final int num, final boolean flag) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(label, num, flag);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("final Main.Named _result;");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("synchronized (_createCache_p) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("if (_createCache_p.containsKey(_cacheKey)) {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("return _createCache_p.get(_cacheKey);");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("Main.Named _xifexpression = null;");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("if (flag) {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("_xifexpression = this.pc();");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("} else {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("_xifexpression = this.pd();");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("_result = _xifexpression;");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("_createCache_p.put(_cacheKey, _result);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("_init_p(_result, label, num, flag);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return _result;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private final HashMap<ArrayList<?>, Main.Named> _createCache_p = CollectionLiterals.newHashMap();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private void _init_p(final Main.Named it, final String label, final int num, final boolean flag) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("it.setName(label);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("((Main.A)it).setNumber(num);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("((Main.B)it).setCount(num);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Ignore("AbstractStringBuilder may not be referenced")
  @Test
  public void test_03() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Main {");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("def create if (sync) new StringBuffer else new StringBuilder p(String value, boolean sync) {");
    _builder.newLine();
    _builder.append("        ");
    _builder.append("append(value) // since append(String) is defined in AbstractStringBuilder, this should link to append(CharSequence)");
    _builder.newLine();
    _builder.append("    ");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.util.ArrayList;");
    _builder_1.newLine();
    _builder_1.append("import java.util.HashMap;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.CollectionLiterals;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class Main {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Object p(final String value, final boolean sync) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("final ArrayList<?> _cacheKey = CollectionLiterals.newArrayList(value, sync);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("final Object _result;");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("synchronized (_createCache_p) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("if (_createCache_p.containsKey(_cacheKey)) {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("return _createCache_p.get(_cacheKey);");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("AbstractStringBuilder _xifexpression = null; <-- should be Object");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("if (sync) {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("_xifexpression = new StringBuffer();");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("} else {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("_xifexpression = new StringBuilder();");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("_result = _xifexpression;");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("_createCache_p.put(_cacheKey, _result);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("_init_p(_result, value, sync);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return _result;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private final HashMap<ArrayList<?>, Object> _createCache_p = CollectionLiterals.newHashMap();");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("private void _init_p(final Object it, final String value, final boolean sync) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("it.append(value); // missing cast to Appendable also missing try catch for IOException");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }
}
